package com.culturalCenter.dataCenter.mapper.user;

import com.culturalCenter.dataCenter.customEntity.user.CustomUserPointChangeCount;
import com.culturalCenter.dataCenter.entity.user.UserPointIncrease;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserPointIncreaseMapper extends BaseMapper<UserPointIncrease> {

    /**
     * 通过用户id查询
     *
     * @param userId 用户id
     *
     * @return
     */
    List<UserPointIncrease> queryByUserId(@Param("userId") String userId);

    /**
     * 通过用户id查询比率
     *
     * @param userId
     *
     * @return
     */
    @Select("SELECT contentType, num, num/sum*100 AS rate FROM cdc_user_point_increase,(SELECT SUM(num) sum FROM cdc_user_point_increase WHERE userId = 'df30e0c6-e9d2-11ea-94ae-0242ac110008')s " +
            "WHERE userId = #{userId};")
    List<CustomUserPointChangeCount> queryRateByUserId(@Param("userId") String userId);

}
